/*****************************************************************************************************
STATA do-file that generates Figure C1 used in the paper: 

Public Sector Employment and Voter Turnout
Benny Geys and Rune J. Sørensen

published in the American Politial Science Review 
*****************************************************************************************************/
clear all

cd 	"E:\Users\FAG89001\OneDrive - BI Norwegian Business School (BIEDU)\PublicSectorTurnout\Tables"  /* Directory for output files */
use "G:\BI_Research\0208_Listekandidater_2019\OutputDta\Vote20132019.dta"
keep if Eligible==1

* NB: Redefine not employed by people with wage income less than 1.000 NOK
replace Sector=0 if Sector==.
replace Sector=0 if wlonn< 1000

* Redefine sector (combining municipal and county government employees)
replace Sector=3 if Sector==4  									/* Combining municipal and county employees to one category */
label define NewSectorLab 0 "No occupation" 1 "Private sector" 2 "Central government" 3 "Local government" 5 "Non-profit sector"
label values Sector NewSectorLab
bysort knr_res year: egen Turnout_sum	=	sum(Vote)  		/* Number of voters  irrespective of sector affiliation */
bysort knr_res year: egen Eligible_sum	=	sum(Eligible) 	/* Size of electorate irrespective of sector  affiliaton */

* Collapsing voter turnout by sector, residential municipality and election years
collapse (mean) Turnout_sum Eligible_sum (sum) Turnout_sector=Vote Eligible_sector=Eligible, by(Sector knr_res year)
gen ShareElectorate		=	Eligible_sector/Eligible_sum
gen Turnout				=	Turnout_sum/Eligible_sum
gen TurnoutSector		=	Turnout_sector/Eligible_sector
gen TurnoutRatio		= 	TurnoutSector/Turnout 	 	
gen ShareVoters			=	Turnout_sector/Turnout_sum
keep knr_res Sector year ShareElectorate TurnoutRatio ShareVoters

* Keeping results for the local elections in 2019
keep if year==2019
reshape wide ShareElectorate TurnoutRatio ShareVoters, i(knr_res) j(Sector)
gen knr=knr_res 
gen knr2020=knr_res

* Exploiting data on support for the socialist parties (at the national level) conditional on institutional affiliation
gen Soc_asis	=	0.4439*ShareVoters0 + 0.3602*ShareVoters1 + 0.5475*(ShareVoters2+ShareVoters3) + 0.4500*ShareVoters5 
gen Soc_equal	=	0.4439*ShareElectorate0 + 0.3602*ShareElectorate1 + 0.5475*(ShareElectorate2+ShareElectorate3) + 0.4500*ShareElectorate5 
gen Soc_diff_pct=	(Soc_asis-Soc_equal)*100 

lab var Soc_asis "Predicted support for left-wing political parties, actual turnout rates"
lab var Soc_equal "Predicted support for left-wing political parties, full turnout for all groups"
lab var Soc_diff  "Socialist party gain relative to full turnout for all groups, (%)"

histogram Soc_diff_pct if year==2019, bin(25) bcolor(navy) gap(5) xtitle("Left-wing party gain (%)") graphregion(color(white))
graph save FigureC1.gph, replace 
graph export FigureC1.tiff, as(tif) replace 